package com.example.module_marketers.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.entity.ParkingEntity
import com.bw.lib_common.vm.BaseViewModel2
import com.example.module_marketers.entity.*
import com.example.module_marketers.model.MarketersRepository
import kotlinx.coroutines.launch

class MarketersViewModel:BaseViewModel2<MarketersRepository>() {
    override fun createRepository(): MarketersRepository= MarketersRepository()

    val  getBusinessProfileSuccess by lazy { MutableLiveData<BusinessProfileEntity>() }
    fun getBusinessProfile(){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getBusinessProfileList()
            if (result.code == 200){
                getBusinessProfileSuccess.postValue(result.data)
            }
        }
    }
    val  getBusinessProfileDetailSuccess by lazy { MutableLiveData<BusinessProfileEntityItem>() }
    fun getBusinessProfileDetail(id:Int){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getBusinessProfileDetailById(id)
            if (result.code == 200){
                getBusinessProfileDetailSuccess.postValue(result.data)
            }
        }
    }

    val  getResidencyApplicationListSuccess by lazy { MutableLiveData<ResidencyApplicationEntity>() }
    fun getResidencyApplicationList(){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getResidencyApplicationList()
            if (result.code == 200){
                getResidencyApplicationListSuccess.postValue(result.data)
            }
        }
    }
    val  addResidencyApplicationSuccess by lazy { MutableLiveData<ResidencyApplicationEntityItem>() }
    fun addResidencyApplication(residencyApplicationEditEntity: ResidencyApplicationEditEntity){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.addResidencyApplication(residencyApplicationEditEntity)
            if (result.code == 200){
                addResidencyApplicationSuccess.postValue(result.data)
            }
        }
    }
    val  getResidencyApplicationDetailByIdSuccess by lazy { MutableLiveData<ResidencyApplicationEntityItem>() }
    fun getResidencyApplicationDetailById(id:Int){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getResidencyApplicationDetailById(id)
            if (result.code == 200){
                getResidencyApplicationDetailByIdSuccess.postValue(result.data)
            }
        }
    }
    val  approveResidencyApplicationSuccess by lazy { MutableLiveData<ResidencyApplicationEntityItem>() }
    fun approveResidencyApplication(id:Int){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.approveResidencyApplication(id)
            if (result.code == 200){
                approveResidencyApplicationSuccess.postValue(result.data)
            }
        }
    }
}